#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: V1Dag.py 
@version:
@time: 2022/03/10 
"""
from TapClientCore.T04_logic.DagforDFS.relations.relation import V2DataFlowMapTable


class V2Dag:

    def __init__(self):
        self.stages = []
        self.data_source_model = {}

    def edge(self, source, sink, relation: V2DataFlowMapTable):
        from pprint import pprint
        source_id = source.node.get('id')
        sink_id = sink.node.get('id')

        # stage create
        _out = {'outputLanes': [sink_id]}
        _input = {'inputLanes': [source_id]}
        _sync_objects = relation.syncObjects

        source.node.update(_out)
        sink.node.update(_input)
        sink.node['syncObjects'] = [_sync_objects]

        self.stages.append(source.node)
        self.stages.append(sink.node)

        # dataSourceModel create
        tmp = {
            "source_databaseType": source.node.get('database_type'),
            "target_databaseType": sink.node.get('database_type'),
            "source_filter_databaseType": "all",
            "target_filter_databaseType": "all",
            "source_connectionId": source.node.get('connectionId'),
            "target_connectionId": sink.node.get('connectionId'),
            "source_connectionName": source.node.get('name'),
            "target_connectionName": sink.node.get('name'),
            "mqType": ""
        }
        if source.node.get('mqType'):
            tmp['mqType'] = source.node.get('mqType')
        self.data_source_model = tmp.copy()


if __name__ == '__main__':
    from pprint import pprint
    from TapClientCore.T04_logic.DagforDFS.node.data_copy_source_node import DataCopySourceNode
    from TapClientCore.T04_logic.DagforDFS.node.data_copy_target_node import DataCopySinkNode

    S = DataCopySourceNode('auto_mysql')
    T = DataCopySinkNode('auto_mysql')
    d = V2Dag()
    d.edge(S, T, V2DataFlowMapTable(
        {'syncObjects': {"objectNames": ["my2"], "type": "table"}})
           )
    pprint(d.stages)
    pprint(d.data_source_model)
